
using GameFramework;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace StarForce
{
    
    /// <summary>
    /// 生成组合地板
    /// </summary>
    public class CreateComposeGround : ICreateGround
    {
        private readonly float m_Left = -2f;

        private readonly float m_Right = 2f;

        private GroundDataList m_GroundDataList;

        private readonly float m_CreateNormalRandom = 0.4f;

        private readonly float m_CreateMoveRandom = 0.3f;

        private readonly float m_CreateComposeRandom = 0.3f;

        private bool m_HasProp = false;

        private float m_PropRandom = 0;

        public float PropRandom
        {
            get { return m_PropRandom; }
            set { m_PropRandom = value; }
        }

        public virtual GroundDataList GetCreateGroundDatas()
        {
            CheckHasProp();
            m_GroundDataList = ReferencePool.Acquire<GroundDataList>();
            double random = Utility.Random.GetRandomDouble();
            if (random<m_CreateNormalRandom)
            {
                //生成普通地板
                CreateSigleGround(m_HasProp);

            }else if(random<m_CreateNormalRandom+m_CreateMoveRandom)
            {
                CreateMoveGround();
            }
            else
            {
                CreateComposeRandom(m_HasProp);
            }

            return m_GroundDataList;
        }

        /// <summary>
        /// 生成单一的地板
        /// </summary>
        public void CreateSigleGround(bool HasProp)
        {
            double rand = Utility.Random.GetRandomDouble();

            if (rand < 0.5)
            {
                GameUtility.CreateNormalGround(m_GroundDataList,GroundType.Normal,HasProp);
            }
            else
            {
                GameUtility.CreateNormalGround(m_GroundDataList,GroundType.FractureGround,HasProp);
            }
        }


        /// <summary>
        /// 生成单独的移动地板
        /// </summary>
        private void CreateMoveGround()
        {
            double rand = Utility.Random.GetRandomDouble();

            float x = rand > 0.5 ? m_Left : m_Right;
            
            m_GroundDataList.Add(x,4,false);
        }
        
        /// <summary>
        /// 生成组合地板
        /// </summary>

        private void CreateComposeRandom(bool HasProp)
        {
            GameUtility.CreateComposeGround(m_GroundDataList,GroundType.Normal,GroundType.FractureGround,HasProp);
        }

        private void CheckHasProp()
        {
            if (m_PropRandom == 0)
            {
                m_HasProp = false;
            }
            else
            {
                double random = Utility.Random.GetRandomDouble();
                if (random < m_PropRandom)
                {
                    m_HasProp = true;
                }
            }
        }
    }
}